﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using TaskHub.wsAccount;
using TaskHub.LocalStorage;
namespace TaskHub
{
    public partial class Register : PhoneApplicationPage
    {
        private ucProgress _Progress;
        private ucProgress Progress
        {
            get
            {
                if (_Progress == null)
                {
                    _Progress = new ucProgress();
                }
                return _Progress;
            }
        }

        public Register()
        {
            InitializeComponent();
        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                Progress.Show();
                TaskHub.wsAccount.AccountSoapClient ws = new TaskHub.wsAccount.AccountSoapClient();
                ws.CreateAccountCompleted += new EventHandler<CreateAccountCompletedEventArgs>(ws_CreateAccountCompleted);
                ws.CreateAccountAsync(this.txtEmail.Text.ToString(), this.txtPhone.Text.ToString(), this.txtName.Text.ToString(), this.txtPwd.Password.ToString());
            }
            catch (Exception)
            {
                throw;
            }
        }

        void ws_CreateAccountCompleted(object sender, CreateAccountCompletedEventArgs e)
        {
            Progress.Hide();
            if (e.Error != null)
            {
                MessageBox.Show(e.Error.Message, "Error", MessageBoxButton.OK);
                return;
            }

            int AccountID = (int) e.Result;
            IsolatedStorageDAO.setMyId(AccountID);
            NavigationService.Navigate (new Uri("/MainPage.xaml"));
        }
       
        private void btnCancel_Click(object sender, EventArgs e)
        {
            NavigationService.GoBack();
        }

        private void linkLogin_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Login.xaml", UriKind.Relative));
        }

        
    }
}